import React from 'react';
import {connect} from 'dva';
import PropTypes from 'prop-types';
import {Link} from 'dva/router'
import {Table, Button,Row,Col,Icon,Layout, Breadcrumb,Input,DatePicker,Dropdown,Popconfirm, message} from 'antd';
// import SelectPageTable from '../../components/SelectPageTable.js';
import style from '../../styles/TableCss.less';
import reqwest from 'reqwest';
// import {PublicCustomer} from '../utils/PublicCode.js'
// import TopUpBoxAmt from './components/TopUpBpxAmt.js'
// console.log(PublicCustomer)
const {  Content, Footer ,Sider} = Layout;
// const { RangePicker } = DatePicker;
function onChange(value, dateString) {
  console.log('Selected Time: ', value);
  console.log('Formatted Selected Time: ', dateString);
}
function onOk(value) {
  console.log('onOk: ', value);
}
class Delaler extends React.Component{
  constructor(props){
    super(props);
    let _this = this;
    this.state={
      data: [],
        pagination: {},
        loading: false,
        selectedRowKeys: [],
        dropDown:'所有客户',
        delalet:[{
          title: '企业名称',
          dataIndex: 'name',
          width: '20%',
        }, {
          title: '联系人',
          dataIndex: 'admin',
          width: '20%',
        }, {
          title: '手机号',
          dataIndex: 'mobile',
        }, {
          title: '状态',
          dataIndex: 'status',
        },{
          title: '操作',
          key: 'action',
          render: (text, record) => (
            <span>
              <a data='1' onClick={this.updata.bind(this,record,text,1)}>通过</a>
              <span className="ant-divider" />
              <a data='-1' onClick={this.updata.bind(this,record,text,-1)}>拒绝</a>
            </span>
          ),
        }]
    }
  }
    // <Popconfirm title="确认删除吗?" onConfirm={(e) => this.onDelete(record.key, e,this)}>
              // <span className="ant-divider" />
                // <a>删除</a>
    //          </Popconfirm>
  updata(text, record,state,b,c){
    console.log(state)
    let _this = this;
    reqwest({
      url: window.host+'/api/accounts/update_apply',
      method: 'post',
      crossOrigin: true,
      data: {
        access_token:localStorage['token'],
        apply_id:record.key,
        state:state
      },
      type: 'json',
    }).then((data) => {
      if(data.status=='success'){
        message.success('更新成功',1,()=>{
          window.location.hash='/app/company?current='+_this.props.location.query.current;
        })
      }else{
        message.warning(data.msg,1)
      }
    }).fail((err)=>{
      console.log(2)
    })
  }
  onDelete(key,e,_this){
    const data = _this.state.data.filter(item => item.key !== key);
    _this.setState({data });
  }
  handleTableChange(pagination, filters, sorter){
    const pager = { ...this.state.pagination };
    // console.log(pagination.current)
    pager.current = pagination.current;
    this.setState({
      pagination: pager,
    });
    this.fetch({
      results: pagination.pageSize,
      page: pagination.current,
      sortField: sorter.field,
      sortOrder: sorter.order,
      ...filters,
    });
  }
  fetch (params = {}) {
    console.log('params:', params);
    let _data=[];
    
    this.setState({ loading: true });
    reqwest({
      url: window.host+'/api/accounts/companies',
      method: 'get',
      crossOrigin: true,
      data: {
        access_token:localStorage['token'],
        page:params.page,
      },
      type: 'json',
    }).then((data) => {
      console.log(data);
        const pagination = { ...this.state.pagination };
      // Read total count from server
      // pagination.total = data.totalCount;
      if(params.page==1){
        pagination.total = data.total;
      }
      // window.sessionStorage['apply']=JSON.stringify(data.select_list);

      for(let i of data.list){
        _data.push({
          key:i.id,
          name:i.dealer_admin,
          admin:i.dealer_name,
          mobile:i.dealer_mobile,
          status:i.state
        })
      }
      this.setState({
        loading: false,
        data: _data,
        pagination,
      });
    });
  }
  componentWillMount(){
    this.fetch({page:1});
  }
  menuClick(e){
    console.log(e.item.props.value)
    this.setState({dropDown:e.item.props.value});
  }
  componentDidMount(){

  }
  render(){
    let compan=null;
    let col=this.state.columns;
    console.log(window.annount_type)
    const { data,pagination,loading,dropDown,columns } = this.state;
    return(
      <Layout style={{background:'#fff',height:'100%'}}>
        <Content >
          <Row >
            <Col  sm={{span:7,offset:0}} xs={{span:9}} style={{padding:'24px 25px 24px'}}>
              品牌审核
            </Col>
            <Col xl={{span :3,offset:13}} lg={{span:3,offset:13}} md={{span:3,offset:13}} sm={{span:3,offset:13}} xs={{span:2,offset:8}} style={{lineHeight:'60px',textAlign:'right'}}>
            </Col>
          </Row>
          <Layout className={`${style.tb_serbor}`}>
            <Row  className={`${style.tb_ser}`}>
              <Col sm={{span:7}} xs={{span:0}}>
              </Col>
              <Col sm={{span:7,offset:10}} xs={{span:14,offset:10}} style={{textAlign:'right'}}>
                
              </Col>
            </Row>
            <Table columns={this.state.delalet}
              dataSource={data} onRowClick={this.handleRowClick}
              pagination={pagination}
              loading={loading}
              onChange={this.handleTableChange.bind(this)}
            />
          </Layout>
        </Content>
      </Layout> 
    )
  }
}
// rowSelection={rowSelection} 批量删除
export default connect()(Delaler);